<?php

class Admin_Form_AddUser extends Custom_Form
{

	private $_user_id = '';

	function  __construct($user_id = '') {
		$this->_user_id = $user_id;
		parent::__construct(null);
	}

	public function init()
    {
		$translate = Zend_Registry::get('translate');
		$passwordConfirmation = new Custom_Validate_PasswordConfirmation();
		
		$this->setTranslator($translate);
	    $this->setName("signup");
        $this->setMethod('post');

		$role	 = new User_Model_DbTable_Role();
        $bank    = new Service_Model_DbTable_Bank();

        $this->addElement('select', 'role_id', array(
            'label'      => __('Role').':',
			'multiOptions' => $role->getOptions(),
		));

        $this->addElement('select', 'bank_id', array(
            'label'      => __('Bank').':',
            'required'   => true,
			'multiOptions' => $bank->getOptions(),
		));

		$this->addElement('text', 'first_name', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 50)),
				array('Alnum'),
			),

            'required'   => true,
            'label'      => __('First Name').':',
        ));

		$this->addElement('text', 'last_name', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 50)),
				array('Alnum'),
            ),
            'required'   => true,
            'label'      => __('Last Name').':',
        ));

        $this->addElement('textarea', 'address', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 255)),
		    ),
            'required'   => true,
            'rows'       => 3,
            'cols'       => 50,
            'label'      => __('Address').':',
        ));

        $this->addElement('text', 'email', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 75)),
				array('EmailAddress'),
				array('Db_NoRecordExists',false,array('table'=>'vt_users','field'=>'email','exclude'=>array('field'=>'id','value'=>$this->_user_id)))
            ),
            'required'   => true,
            'label'      => __('Email').':',
        ));


		$this->addElement('password', 'password', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(8, 50)),
				array('Alnum'),
			),
            'required'   => (!$this->_user_id)?true:false,
            'label'      => __('Password').':',
        ));

		//user form validation message
		$this->first_name->addErrorMessage('ERR_INVALID_FIRST_NAME');
		$this->last_name->addErrorMessage('Err_INVALID_LAST_NAME');
		$this->email->addErrorMessage('ERR_INVALID_EMAIL');
		$this->password->addErrorMessage('ERR_INVALID_PASSWORD');

		$this->addElement('submit', 'save', array(
            'required' => false,
            'ignore'   => true,
            'label'    => __('Save'),
        ));

		$this->save->removeDecorator('label');
	}
}